package com.app.Activity;

import it.unipr.ce.dsg.s2p.sip.Address;

import java.util.ArrayList;

import com.app.Controller.NetworkController;
import com.app.Controller.ReadWriteFileController;
import com.app.Network.Protocol;
import com.app.PhanQuyen.Quyen;

import ReadWriteXML.CMember;
import ReadWriteXML.ReadXML;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.util.Log;
import android.view.ContextMenu;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ContextMenu.ContextMenuInfo;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import app.com.ModuleRole.R;

public class frmDanhSachThanhVienActivity extends Activity {
	int port = Protocol.PORT;
	ListView lvDanhSachThanhVien;

	ArrayList<CMember> memberList;
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.layout_danh_sach_thanh_vien);
		lvDanhSachThanhVien = (ListView) findViewById(R.id.lvDanhSachThanhVien);
		fillListView();
		registerForContextMenu(lvDanhSachThanhVien);


	}

	
	private void fillListView() {
		 memberList = ReadXML.ReadMember(ReadWriteFileController.MEMBER_PATH);
		ArrayAdapter<CMember> adapter = new ArrayAdapter<CMember>(this, android.R.layout.simple_list_item_1, memberList);
		lvDanhSachThanhVien.setAdapter(adapter);
	}

	@Override
	public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
		if (v.getId() == R.id.lvDanhSachThanhVien) {
			AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
			menu.setHeaderTitle("Thao tác");
			menu.addSubMenu(Menu.NONE, 1, 1, "Mời ra khỏi nhóm");
			menu.addSubMenu(Menu.NONE, 2, 2, "Chat riêng");
			menu.addSubMenu(Menu.NONE, 3, 3, "Yêu cầu ngừng thảo luận");
		}
	}

	@Override
	public boolean onContextItemSelected(MenuItem item) {
		AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
		int menuItemIndex = item.getItemId();
		if (menuItemIndex == 1) {
			
			//ShowSetTimeVoteKick(memberList.get(info.position).get_ip());
			Intent data=new Intent();
			data.putExtra(trucActivity.IP_RESULT, memberList.get(info.position).get_ip());
			setResult(RESULT_OK, data);
			finishActivity(trucActivity.CODE_KICK);
			Toast.makeText(getBaseContext(), "mời ra khỏi nhóm", 1).show();
			
		} else if (menuItemIndex == 2) {
			Toast.makeText(getBaseContext(), "Chat riêng", 1).show();
		} else if (menuItemIndex == 3) {
			Toast.makeText(getBaseContext(), "Yêu cầu ngừng thảo luận", 1).show();
			//ShowSetTimeVoteKick();
		}
		return true;
	}

}
